package com.handydata.antifraud.config;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import lombok.extern.log4j.Log4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;


/**
 * @Author wuzhiguo
 * @Date 2020/04/29 20:56
 */

@Configuration
@EnableAsync
@Log4j
public class ThreadPoolExecutorConfig {
    public static final int PROCESSORS=Runtime.getRuntime().availableProcessors();

    @Bean
    public ThreadPoolTaskExecutor taskExeption() {
        System.out.println("CPU核数"+PROCESSORS);
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize((PROCESSORS * 2));
        executor.setMaxPoolSize((PROCESSORS * 4));
        executor.setQueueCapacity(500);
        executor.setThreadNamePrefix("HD-QUERY-THREAD:");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }
}